#pragma once

#include "nml_intf/zuc.hh"
#include "rcs.hh"
#include "cmd_msg.hh"
#include "stat_msg.hh"

#include "zuc/nml_intf/zucpos.h"

void FuncIOMap_update(CMS* cms, FuncIOMap* x);
void FuncIOReq_update(CMS* cms, Func_IO_Req_t* x);

class ZUC_EXTIO_STAT
{
public:
    ZUC_EXTIO_STAT() {}
    // configs
    int extIOModCnt;
    ExtIOModConfig extIOConfig[MAX_EXTIO_CNT];

    // feedback
    ExtIOStat extIOStat;

    void update(CMS* cms);
};
class ZUC_TIO_STAT
{
public:
    ZUC_TIO_STAT() {}
    TIOStatus tioStatus;
    TIOConfig tioConfig;
    GripperStateUnit gripperState[MAX_TIO_SIG_NUM];

    uint8_t freeButtonOpt;        //free按键
    uint8_t secondfreeButtonOpt;  //薄膜按键
    uint8_t progButtonOpt;        //薄膜按键
    uint8_t pointButtonOpt;       //point按键

    short rs485_msg[100];
    int rs485_msg_len;
};

class ZUC_IO_STAT
{
public:
    ZUC_IO_STAT() {}

    void update(CMS* cms);

    ZUC_EXTIO_STAT extio;  // setting and status of extended IO

    int synch_di[ZUCMOT_MAX_DIO];         // motion inputs queried by interp
    int synch_do[ZUCMOT_MAX_DIO];         // motion outputs queried by interp
    float analog_input[ZUCMOT_MAX_AIO];   // motion analog inputs queried by interp
    float analog_output[ZUCMOT_MAX_AIO];  // motion analog outputs queried by interp

    int synch_mb_slave_di[ZUCMOT_MAX_MODBUS_DIO];
    int synch_pn_dev_di[ZUCMOT_MAX_PNDev_DIO];
    int synch_eip_adpt_di[ZUCMOT_MAX_EIP_DIO];
    unsigned char synch_eip_in[492];
    unsigned char synch_eip_out[492];

    int synch_mb_slave_do[ZUCMOT_MAX_MODBUS_DIO];
    int synch_pn_dev_do[ZUCMOT_MAX_PNDev_DIO];
    int synch_eip_adpt_do[ZUCMOT_MAX_EIP_DIO];

    float analog_mb_slave_input[ZUCMOT_MAX_MODBUS_AIO_NUM];
    float analog_pn_dev_input[ZUCMOT_PNDev_INT_AIO_NUM + ZUCMOT_PNDev_FLOAT_AIO_NUM];
    float analog_eip_adpt_input[ZUCMOT_EIP_INT_AIO_NUM + ZUCMOT_EIP_FLOAT_AIO_NUM];

    float analog_mb_slave_output[ZUCMOT_MAX_MODBUS_AIO_NUM];
    float analog_pn_dev_output[ZUCMOT_PNDev_INT_AIO_NUM + ZUCMOT_PNDev_FLOAT_AIO_NUM];
    float analog_eip_adpt_output[ZUCMOT_EIP_INT_AIO_NUM + ZUCMOT_EIP_FLOAT_AIO_NUM];

    int profinet_state;  // profinet
    int eip_state;       // EthernetIP
    char eip_mode;
    short eip_di_num;
    short eip_do_num;
    short eip_ai_int_num;
    short eip_ai_float_num;
    short eip_ao_int_num;
    short eip_ao_float_num;
    uint8_t di_type_pin_g1;  //cabv3 di type for pin [0,7]
    uint8_t di_type_pin_g2;  //cabv3 di type for pin [8,15]
    uint8_t do_type_pin_g1;  //cabv3 do type for pin [0,7]
    uint8_t do_type_pin_g2;  //cabv3 do type for pin [8,15]

    int scb_anachn_setting;
    int scb_digchn_setting;

    FuncIOMap funcIOMap;
    Func_IO_Req_t func_io_req;
    UhiData uhiData;
};